#pragma once
#include "DXAMLCommon.h"
#include "IPALCriticalSection.h"


#include "_XContiguousBlock.h"
#include "IPALDebuggingServices.h"


class XFixedSizeAllocator
{
public: 
	XFixedSizeAllocator();
	~XFixedSizeAllocator();
	HRESULT Initialize(XUINT32 uItemSize, XUINT32 uSlotsPerBlock, XUINT32 uMaxNumberOfBlocks, XUINT32 uInitialNumberOfBlocks);
	void Cleanup(XUINT32 & outLeakedItems);
	XUINT8 * Allocate();
	HRESULT Release(XUINT8 * pBufferToFree);
private: 
	HRESULT GrowBlockArray();
	static const XUINT32 INITIAL_BLOCK_ARRAY_SIZE;
	_XContiguousBlock * * m_pBlocks;
	XUINT32 m_uNumberOfBlocks;
	XUINT32 m_uSlotsPerBlock;
	XUINT32 m_uMaxNumberOfBlocks;
	XUINT32 m_uItemSize;
	struct IPALCriticalSection * m_pcsBlocks;
};

